package com.androidcourse.changeandget;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

import com.androidcourse.changeandget.Database.DBHelper;
import com.androidcourse.changeandget.User.Good;
import com.androidcourse.changeandget.User.User;

import java.util.ArrayList;

public class PersonalInfo extends AppCompatActivity {
    private String SID;
    private String changename;
    private String changetele;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal_info);

        Intent intent = getIntent();
        //从Intent中取出Bundle
        Bundle bundle = intent.getExtras();
        //获取FunPerson里的数据数据
        assert bundle != null;
        SID =bundle.getString("person");//当前用户
        System.out.println(SID);
        //Toast.makeText(PersonalInfo.this,person.getId(), Toast.LENGTH_SHORT).show();

        Spinner spinner_estate=findViewById(R.id.spi_estate);
        spinner_estate.setSelection(0);		//初始化，默认选择列表中第0个元素
        spinner_estate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                // TODO
                String input_p_estate;
                if (pos==1){
                    input_p_estate="第二小区";
                }
                else if(pos==2){
                    input_p_estate="第三小区";
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // TODO
            }
        });
        DBHelper msqlite = new DBHelper(PersonalInfo.this);
        Button update=(Button) findViewById(R.id.update);
        EditText name=(EditText) findViewById(R.id.name);
        EditText phone=(EditText) findViewById(R.id.phone);
        Spinner  spi_estate=(Spinner) findViewById(R.id.spi_estate);
        Spinner spi_sex=(Spinner) findViewById(R.id.spi_sex);

        update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                changename=name.getText().toString();
                changetele=phone.getText().toString();

                if(msqlite.changeStudentData(changename,changetele,SID)){
                    Toast.makeText(PersonalInfo.this, "上传成功", Toast.LENGTH_SHORT).show();
                    finish();
                }else{
                    Toast.makeText(PersonalInfo.this, "上传失败", Toast.LENGTH_SHORT).show();
                }






            }
        });

        Spinner spinner_sex=findViewById(R.id.spi_sex);
        spinner_sex.setSelection(0);		//初始化，默认选择列表中第0个元素
        spinner_sex.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                // TODO
                String input_p_sex;
                if (pos==1){
                    input_p_sex="男";
                }
                else if(pos==2){
                    input_p_sex="女";
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // TODO
            }
        });


    }
}
